﻿using System;
using System.Data;


namespace EQT.Model
{



    /// <summary>
    /// UserContext 的摘要说明
    /// </summary>
    public class UserContext
    {
        #region 角色定义常量
        public const string ROLE_ID_TESTER_GROUP = "TesterGroup";
        public const string ROLE_ID_TESTER_GROUP_DDL = "TesterGroup_DDL";
        public const string ROLE_ID_TESTER_GROUP_QDL = "TesterGroup_QDL";
        public const string ROLE_ID_REPORT_GROUP = "ReportGroup";
        public const string ROLE_ID_BUSINESS_GROUP = "BusinessGroup";
        public const string ROLE_ID_BACKSERVICE_GROUP = "BackServiceGroup";
        public const string ROLE_ID_ADMINISTRATORS = "Administrators";
        #endregion

        public UserContext()
        {
        }

        /// <summary>
        /// 有效的用户
        /// </summary>
        private bool IsValidUser
        {
            get
            {
                return (tuser != null) && (userRole != null) && (trole != null);
            }
        }

        /// <summary>
        /// 有效的用户且是员工
        /// </summary>
        private bool IsValidEmpUser
        {
            get
            {
                return IsValidUser && (emp != null) && (dept != null);
            }
        }
        #region 员工信息，用户信息，部门信息，角色

        private MoTuser tuser;
        /// <summary>
        /// 用户
        /// </summary>
        public MoTuser TUser
        {
            get { return tuser; }
            set { tuser = value; }
        }

        private MoEmployee emp;
        /// <summary>
        /// 员工
        /// </summary>
        public MoEmployee Emp
        {
            get { return emp; }
            set { emp = value; }
        }


        private MoDept dept;
        /// <summary>
        /// 单位
        /// </summary>
        public MoDept Dept
        {
            get { return dept; }
            set { dept = value; }
        }

        private MoUserRole userRole;
        /// <summary>
        /// 用户角色
        /// </summary>
        public MoUserRole UserRole
        {
            get { return userRole; }
            set { userRole = value; }
        }

        private MoTrole trole;
        /// <summary>
        /// 角色（目前系统只支持一个用户一个角色）
        /// </summary>
        public MoTrole TRole
        {
            get { return trole; }
            set { trole = value; }
        }



        #endregion

        #region 用户
        public string UserID
        {
            get 
            {
                if (tuser != null) return tuser.Uid;
                return String.Empty;
            }           
        }

      

        public string UserName
        {
            get
            {
                if (tuser != null) return tuser.DisplayName;
                return String.Empty;
            }            
        }

       
        public string RoleID
        {
            get 
            {
                if (userRole != null) return userRole.RoleId;
                return String.Empty; 
            }
           
        }

        
        public string RoleName
        {
            get
            {
                if (trole != null) return trole.RoleName;
                return String.Empty;
            }

        }
        #endregion

        #region 员工信息
        public string EmpID
        {
            get 
            {
                if (emp != null) return emp.EmpId;
                return String.Empty; 
            
            }
           
        }

     
        public string EmpName
        {
            get
            {
                if (emp != null) return emp.Fullname;
                return String.Empty;
            }
           
        }

      
        public string DeptID
        {
            get 
            {
                if (dept != null) return dept.DeptId;
                return String.Empty;
            
            }
            
        }

       
        public string DeptName
        {
            get
            {
                if (dept != null) return dept.DeptName;
                return String.Empty;
            }

        }
        #endregion

        //Note:应该把角色对应的功能菜单Cache

    }
}
